package com.penghaisoft.microwms.base.web.data.service.impl;


import javax.annotation.Resource;
import com.penghaisoft.microwms.base.web.contract.dao.MdContractMapper;
import com.penghaisoft.microwms.base.web.data.service.IMdContractService;
import com.penghaisoft.microwms.common.data.model.MdContract;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.service.BaseService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * <p>
 * 业务逻辑实现类
 * </p>
 * 
 * @author
 * @createDate 
 **/
@Service
public class MdContractServiceImpl extends BaseService implements IMdContractService {
		@Resource
		private MdContractMapper mdContractMapper;
		
	  /**
	   * 新增记录
	   * @param
	   * @return
	   */
		@Override
		public Resp create(MdContract mdContract){
			mdContract.setActiveFlag("1");
			mdContract.setGmtCreate(new Date());
			mdContractMapper.create(mdContract);
			return success();
		}

	  /**
	   * 删除记录（逻辑删除）
	   * @param mdContract
	   * @return
	   */
		@Override
		public Resp delete(MdContract mdContract){
			mdContract.setGmtModified(new Date());
			mdContractMapper.delete(mdContract);
			return success();
		}
		
	  /**
	   * 查询列表
	   * @return
	   */
		@Override
		public Pager<MdContract> findListByCondition(int page, int rows, MdContract condition){
		    Pager<MdContract> pager = new Pager<>();
		    pager.setPage(page);
		    pager.setRows(rows);
    		condition.preQuery();
			List<MdContract> records = mdContractMapper.queryList(pager,condition);
			long size = mdContractMapper.queryCount(condition);
			pager.setRecords(records);
			pager.setTotalCount(size);
			return pager;
		}

	  /**
	   * 查询单条
	   * @param id
	   * @return
	   */
		@Override
		public MdContract findById(String id){
			return mdContractMapper.queryById(id);
		}
		
	  /**
	   * 修改记录
	   * @param
	   * @return
	   */
		@Override
		public Resp update(MdContract mdContract){
			mdContractMapper.updateBySelect(mdContract);
			return success();
		}
		
		/** 
		 * @Title queryList
		 * @Description 查询列表
		 * @author luoteng
		 * @date 2018年5月28日:上午10:11:27
		 * @param condition
		 * @return
		 */
		@Override
		public List<MdContract> queryList(MdContract condition){
			return mdContractMapper.queryByAny(condition);
		}

}
